<?php

use console\db\channels\TransferTableMigration;

/**
 * 圈子帖子图片表迁移
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m300020_000005_t_sns_dynamic_gallery extends TransferTableMigration {

    /**
     * @inheritdoc
     */
    public $sourceDb = 'olddb';

    /**
     * @inheritdoc
     */
    public function getTransferOptions() {
        return [
            'table' => [
                'sns_dynamic_gallery' => 'sns_group_thread_pic'
            ],
            'columns' => [
                'user_id' => 'uid',
                'dynamic_id' => 'tid',
                'comment_id' => 'postid',
                'original' => function($data) {
                    if ($data['picurl']) {
                        if (strpos($data['picurl'], 'http') !== false) {
                            return $data['picurl'];
                        }
                        return '/uploads/' . ltrim($data['picurl'], '/');
                    }
                    return '';
                },
            ],
        ];
    }

}
